﻿using System.Collections.Generic;
using System;
using System.Windows.Controls;
using SgpaServer.Model.Entities;
using System.Linq;
using SqlSugarMod.Entities;

namespace SqlSugarMod.Views;
/// <summary>
/// Interaction logic for SqlSugarMain
/// </summary>
public partial class SqlSugarMain : UserControl
{
    public SqlSugarMain()
    {
        InitializeComponent();
    }

    private void BtConnectSqlSugar_Click(object sender, System.Windows.RoutedEventArgs e)
    {
        //初始化数据库连接
        PGSql.InitialPGSql("127.0.0.1", "5432", "ZqDoc", "postgres", "Admin123", false);
        //var tableInfos = PGSql.PG_db.DbMaintenance.GetTableInfoList(false);//true 走缓存 false不走缓存
        //var dat = PGSql.GetPostgreDateTime();
        //var employeeTable = tableInfos.Where(t=>t.Name == "Employee").FirstOrDefault();
        //var ss = PGSql.PG_db.Queryable(employeeTable.Name, employeeTable.Name).ToList();
        //查询数据
        Console.WriteLine("----新查询----");
        List<Employee> userList = QueryEmployee.QueryUserName();
        int count = userList.Count;

    }

    private void BtCreateDbTable_Click(object sender, System.Windows.RoutedEventArgs e)
    {
        PGSql.InitialPGSql("127.0.0.1", "5432", "ZqDocx", "postgres", "Admin123", false);
        //PGSql.PG_db.DbMaintenance.CreateDatabase();/***创建单个表***/
        //PGSql.PG_db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(CodeFirstTable1));//这样一个表就能成功创建了
        List<CodeFirstTable1> userList = QueryCodeFirstTable.Query();

    }

    private void BtQueryCompany_Click(object sender, System.Windows.RoutedEventArgs e)
    {
        PGSql.InitialPGSql("127.0.0.1", "5432", "ZqDoc", "postgres", "Admin123", false);
        List<Company> userList = QueryCompany.Query();
        int count = userList.Count;
    }
}
